package com.java.zhuiyun.api.back_course.mapper;

import com.java.zhuiyun.api.back_course.entity.BackCourse;
import com.java.zhuiyun.api.back_course.model.BackCourseModel;
import com.java.zhuiyun.api.course_unit.entity.CourseUnit;
import com.java.zhuiyun.api.dict_navigation_tabs.entity.SysDictPc;
import com.java.zhuiyun.api.sys_dict.entity.SysDict;
import com.java.zhuiyun.api.teacher.entity.Teacher;
import com.java.zhuiyun.common.mapper.BaseMapper;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;

/**
 * @InterfaceName BackCourseMapper
 * @Description TODO
 * @Author 杨友朋
 * @Date 2023/8/14 15:17
 **/
@Mapper
public interface BackCourseMapper extends BaseMapper<BackCourse> {
    /**
     * @Author 杨友朋
     * @Description TODO 查询课程
     * @Date 2023/8/14 16:42
     * @Return
     * @param backCourse,pageRequest
     */
    @Select("<script>SELECT * FROM course c,teacher t" +
            " WHERE c.teacher_id=t.id AND c.del_flag=0 AND t.del_flag=0" +
            "<if test='teacherName!=null and teacherName!=&quot;&quot;'> and t.teacher_name like concat('%',#{teacherName},'%')</if>"+
            "<if test='courseTitle!=null and courseTitle!=&quot;&quot;'> and c.course_title like concat('%',#{courseTitle},'%')</if>"+
            "<if test='courseStatus!=null and courseStatus!=&quot;&quot;'> and c.course_status =#{courseStatus}</if>"+
            "</script>")
    List<BackCourseModel> selectCourse(BackCourseModel backCourse);
    /**
     * @Author 杨友朋
     * @Description TODO 根据id单查课程
     * @Date 2023/8/15 20:59
     * @Return
     * @param
     */
    @Select("SELECT c.*,t.teacher_name,d.dict_name FROM course c,teacher t,sys_dict d WHERE c.teacher_id=t.id AND c.del_flag=0 AND t.del_flag=0 AND c.id=#{id} AND c.subject_id =d.id")
    BackCourseModel selectCourseById(Integer id);

    /**
    * @Author 杨友朋
    * @Description TODO 删除课程
    * @Date 2023/8/17 19:51
    * @Return
    * @param
    */
    @Update("update course set del_flag=1 where id=#{id}")
    Integer delCourse(Integer id);

    /*
     * @Author WX
     * @Description 查询课程数据
     * @Date 2023/8/28 8:44
     * @Return
     * @param null
     */
    @Select("select * from sys_dict where del_flag=0 and dict_type=#{d}")
    List<SysDictPc> selectDict(String d);

    @Update("<script>update course set " +
            "<if test='courseTitle!=null'>course_title=#{courseTitle},</if> " +
            "<if test='courseInfo!=null'>course_info=#{courseInfo},</if> " +
            "<if test='courseImg!=null'>course_img=#{courseImg},</if> " +
            "<if test='payType!=null'>pay_type=#{payType},</if> " +
            "<if test='coursePrice!=null'>course_price=#{coursePrice},</if> " +
            "<if test='updateTime!=null'>update_time=#{updateTime}, </if> " +
            "<if test='subjectId!=null'>subject_id=#{subjectId} </if> " +
            "where id=#{id}</script>")
    int updateCourse(BackCourse backCourse);

    /**
     * @Author 杨友朋
     * @Description TODO 更改状态
     * @Date 2023/8/24 9:23
     * @Return
     * @param
     */
    @Update("update course set course_status=#{courseStatus},up_time=#{upTime},update_time=#{updateTime} where id=#{id}")
    Integer updateSwitch(BackCourse backCourse);

    @Select("<script>SELECT * FROM course c,teacher t" +
            " WHERE c.teacher_id=t.id AND c.del_flag=0 AND t.user_id=#{id} AND t.del_flag=0" +
            "<if test='teacherName!=null and teacherName!=&quot;&quot;'> and t.teacher_name like concat('%',#{teacherName},'%')</if>"+
            "<if test='courseTitle!=null and courseTitle!=&quot;&quot;'> and c.course_title like concat('%',#{courseTitle},'%')</if>"+
            "<if test='courseStatus!=null and courseStatus!=&quot;&quot;'> and c.course_status =#{courseStatus}</if>"+
            "</script>")
    List<BackCourseModel> teacherSelectCourse(BackCourseModel backCourse);

    @Select("SELECT * from teacher where user_id=#{userId}")
    Teacher selectTeacherId(Integer userId);
}
